Skip to content

Conversation

@asajjad2
Copy link
Contributor

@asajjad2 asajjad2 commented Dec 3, 2025

What are the relevant tickets?

Fixes https://github.com/mitodl/hq/issues/9423

Description (What does it do?)

When users register with numbers-only names (e.g., 15418306) and their email local part is also numbers-only (e.g., [email protected]), the usernameify function fails with a ValueError. This is because The USERNAME_INVALID_CHAR_PATTERN constant includes [\d] which removes all digits from usernames to comply with Open edX's requirement that usernames cannot be entirely numeric.

This PR, instead of raising a ValueError when both name and email fail to produce a username, we now generate a random username as a fallback. This ensures users can still register successfully even with edge case inputs.

How can this be tested?

  1. Register a new user on MITxOnline with a completely numeric name and numeric email.
  2. Verify you don't get https://mit-office-of-digital-learning.sentry.io/issues/6903551870/?referrer=github_integration
  3. Verify the edx user against your user has a random edx username attached to it

Additional Context

This is mostly a fallback strategy and the original issue would be resolved through validation checks within MITxOnline forms.

@jkachel jkachel self-assigned this Dec 5, 2025
Copy link
Contributor

@jkachel jkachel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants